package com.spic.business.train.examination.controller;

import com.spic.business.train.examination.domain.TrainPaper;
import com.spic.business.train.examination.service.ITrainPaperService;
import com.spic.common.core.domain.R;
import com.spic.common.core.utils.SecurityUtils;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 试卷Controller
 *
 * @author qishaoping
 * @date 2021-10-21
 */
@RestController
@RequestMapping("/examination")
public class TrainPaperController extends BaseController
{
    @Autowired
    private ITrainPaperService trainPaperService;

    /**
     * 查询试卷列表
     */
    @PreAuthorize(hasPermi = "business/train:examination:list")
    @GetMapping("/list")
    public TableDataInfo list(TrainPaper trainPaper)
    {
        startPage();
        List<TrainPaper> list = trainPaperService.selectTrainPaperList(trainPaper);
        return getDataTable(list);
    }

    /**
     * 导出试卷列表
     */
    @PreAuthorize(hasPermi = "business/train:examination:export")
    @Log(title = "试卷", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TrainPaper trainPaper) throws IOException
    {
        List<TrainPaper> list = trainPaperService.selectTrainPaperList(trainPaper);
        ExcelUtil<TrainPaper> util = new ExcelUtil<TrainPaper>(TrainPaper.class);
        util.exportExcel(response, list, "试卷数据");
    }

    /**
     * 获取试卷详细信息
     */
    @PreAuthorize(hasPermi = "business/train:examination:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(trainPaperService.selectTrainPaperById(id));
    }

    /**
     * 新增试卷
     */
    @PreAuthorize(hasPermi = "business/train:examination:add")
    @Log(title = "试卷", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TrainPaper trainPaper)
    {
        return toAjax(trainPaperService.insertTrainPaper(trainPaper));
    }

    /**
     * 修改试卷
     */
    @PreAuthorize(hasPermi = "business/train:examination:edit")
    @Log(title = "试卷", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TrainPaper trainPaper)
    {
        return toAjax(trainPaperService.updateTrainPaper(trainPaper));
    }

    /**
     * 删除试卷
     */
    @PreAuthorize(hasPermi = "business/train:examination:remove")
    @Log(title = "试卷", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trainPaperService.deleteTrainPaperByIds(ids));
    }
}
